package TUILayer;
import java.util.Scanner;
import java.util.ArrayList;
import ModelLayer.*;
/**
 * User interface to the DVD controller
 * @author(kbh)
 * @version(2005.03.31)
 * (FEN): 2006.02.24: Comments translated into English
 * (FEN): 2006.03.21: Some changes to the architecture in order to assure layering
 *                    and loose coupling
 * (KBH): 2008.10.24: dvdmenu changed to If                   
 */

public class DvdUI
{
    private Scanner keyboard;
    private Scanner keyboardString;
    
    public DvdUI()
    {
        this.keyboard = new Scanner(System.in);
        this.keyboardString = new Scanner(System.in);
    }
    
    public int readInt() 
    {
        int i = 0;
        boolean ok = false;
        
        while(!ok) {
            try {
                i = this.keyboard.nextInt();
                ok = true;
            }catch(Exception e) {
                this.keyboard.nextLine();
            }
        }
        return i;
    }
    
    public double readDouble() 
    {
        double d = 0;
        boolean ok = false;
        
        while(!ok) {
            try {
                d = this.keyboard.nextDouble();
                ok = true;
            }catch(Exception e) {
                this.keyboard.nextLine();
            }
        }
        return d;
    }
   
    public String readLine() 
    {
        String string = keyboardString.nextLine();
        return string;
    }
    
    public void writeBlankLine() 
    {
        System.out.println("");
    }
    
    public void clearConsole() 
    {
        System.out.println("\f");
    }
    
    public void writeDVDMenu()
    {
            System.out.println("\f *** DVD Menu ***");
            System.out.println(" (1) Show DVD information");
            System.out.println(" (2) Create DVD");
            System.out.println(" (3) Add DVD copies");
            System.out.println(" (4) Delete DVD");
            System.out.println(" (5) Show current DVD list");
            System.out.println("");
            System.out.println(" (9) Return");
            System.out.print("\n Make your choise: ");
    }
    
    public void writeEnterToContinue() 
    {
        System.out.print("> Press enter to continue");
    }
    
    public void writeSaveOK() 
    {
        System.out.println("The DVD was updated!");
    }
    
    public void writeUpdateOK() 
    {
        System.out.println("The DVD was updated!");
    }
    
    public void writeInputDvdID()
    {
        System.out.print(" Id: ");
    }
    
    public void writeInputTitle()
    {
         System.out.print(" Title: ");
    }
    
    public void writeInputTitle(String title)
    {
         System.out.print(" Title: " + title + ": ");
    }
    
    public void writeInputArtist()
    {
         System.out.print(" Artist: ");
    }
    
    public void writeInputArtist(String artist)
    {
         System.out.print(" Artist: " + artist + ": ");
    }
    
    public void writeInputReleaseDate()
    {
         System.out.print(" Release date: ");
    }
    
    public void writeInputReleaseDate(String date)
    {
         System.out.print(" Release date: " + date + ": ");
    }
    
    
    public void writeInputSerial()
    {
        System.out.print(" Serialnumber: ");
    }
    
    public void writeInputSerial(String serial)
    {
        System.out.print(" Serialnumber: " + serial + ": ");
    }
    
    public void writeInputReqDate()
    {
        System.out.print(" Requisition date: ");
    }
    
    public void writeInputReqDate(String reqDate)
    {
        System.out.print(" Requisition date: " + reqDate + ": ");
    }
    
    public void writeInputBuyPrice()
    {
        System.out.print(" Buy price: ");
    }
    
    public void writeInputBuyPrice(double buyPrice)
    {
        System.out.print(" Buy price: " + buyPrice + ": ");
    }
    
    public void showId(int id)
    {
        System.out.println("ID of the DVD: " + id);
    }
    
    public void showTitle(String title)
    {
        System.out.println("Title of the DVD: " + title);
    }
    
    public void showArtist(String artist)
    {
        System.out.println("Artist of the DVD: " + artist);
    }
    
    public void showReleaseDate(String date)
    {
        System.out.println("Release date of the DVD: " + date);
    }
    
    public void writeSelectDvdId() 
    {
        System.out.print("Enter a ID of a DVD to continue: ");
    }
    
    public void writeCreateNewDvd() 
    {
        System.out.println("Add new dvd:\n==============");
    }
    
    public void writeDvdCollection() 
    {
        System.out.println("\fDVD collection:");
    }
    
    
    public void writeOutDvd(ArrayList<Dvd> dvd) 
    {
        if(dvd.size() > 0) {
            for(Dvd d : dvd) {
               System.out.println(d.getId() + ": " + d.getTitle());
            }
        } else {
            System.out.println("There are no DVD in the list!");
        }
    }
    
    public void writeDvdCollection(Dvd dvd) 
    {
        System.out.println("=== DVD details ===");
        System.out.println("Id: " + dvd.getId());
        System.out.println("Title: " + dvd.getTitle());
        System.out.println("Artist: " + dvd.getArtist());
        System.out.println("ReleaseDate: " + dvd.getReleaseDate());
    }
       
}